﻿using System;
using System.Windows.Forms;
using ShippingManage.DataAccessor.Entities;
using ShippingManage.Models;

namespace ShippingManage
{
	public partial class frmShipping : FormBase
	{
		public frmShipping()
		{
			InitializeComponent();
		}
		#region validate data

		private void txtLastNameSender_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtLastNameSender.Text.Length == 0)
			{
				error = "Please enter a last name";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtMiddleNameSender_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtMiddleNameSender.Text.Length == 0)
			{
				error = "Please enter a middle name";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtFirstNameSender_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtFirstNameSender.Text.Length == 0)
			{
				error = "Please enter a first name";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtAddressSender_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtAddressSender.Text.Length == 0)
			{
				error = "Please enter a address";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtCitySender_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtCitySender.Text.Length == 0)
			{
				error = "Please enter a city";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtStateSender_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtStateSender.Text.Length == 0)
			{
				error = "Please enter a state";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtZipCodeSender_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtZipCodeSender.Text.Length == 0)
			{
				error = "Please enter a zipcode";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtPhoneSender_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtPhoneSender.Text.Length == 0)
			{
				error = "Please enter a telephone";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtEmailSender_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtEmailSender.Text.Length == 0)
			{
				error = "Please enter a email";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtLastNameReceive_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtLastNameReceive.Text.Length == 0)
			{
				error = "Please enter a last name";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtMiddleNameReceive_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtMiddleNameReceive.Text.Length == 0)
			{
				error = "Please enter a middle name";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtFirstNameReceive_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtFirstNameReceive.Text.Length == 0)
			{
				error = "Please enter a first name";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtAddressReceive_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtAddressReceive.Text.Length == 0)
			{
				error = "Please enter a address";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtCityReceive_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtCityReceive.Text.Length == 0)
			{
				error = "Please enter a city";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtStateReceive_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtStateReceive.Text.Length == 0)
			{
				error = "Please enter a state";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtZipcodeReceive_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtZipcodeReceive.Text.Length == 0)
			{
				error = "Please enter a zipcode";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtPhoneReceive_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtPhoneReceive.Text.Length == 0)
			{
				error = "Please enter a telephone";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtEmailReceive_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtEmailReceive.Text.Length == 0)
			{
				error = "Please enter a email";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtTotalPackage_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtTotalPackage.Text.Length == 0)
			{
				error = "Please enter a total package";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtLenght_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtLenght.Text.Length == 0)
			{
				error = "Please enter a lenght";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtWidth_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtWidth.Text.Length == 0)
			{
				error = "Please enter a with";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtHeight_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtHeight.Text.Length == 0)
			{
				error = "Please enter a height";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtTotalWeight_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtTotalWeight.Text.Length == 0)
			{
				error = "Please enter a total weight";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtDeclaredValue_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtDeclaredValue.Text.Length == 0)
			{
				error = "Please enter a declared";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtInsurance_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtInsurance.Text.Length == 0)
			{
				error = "Please enter a insurance";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtUnitPrice_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtUnitPrice.Text.Length == 0)
			{
				error = "Please enter a unit price";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtTaxableAmount_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtTaxableAmount.Text.Length == 0)
			{
				error = "Please enter a tax able amount";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtExtraCharge_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtExtraCharge.Text.Length == 0)
			{
				error = "Please enter a ExtraCharge";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtTotalCharge_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtTotalCharge.Text.Length == 0)
			{
				error = "Please enter a totalCharge";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtSenderSignature_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtSenderSignature.Text.Length == 0)
			{
				error = "Please enter a Sender signature";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtSenderDriver_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtSenderDriver.Text.Length == 0)
			{
				error = "Please enter a sender driver";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtEmployeeSignature_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtEmployeeSignature.Text.Length == 0)
			{
				error = "Please enter a employee signature";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtDate_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtDate.Text.Length == 0)
			{
				error = "Please enter a date";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}

		private void txtCustomerID_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			string error = null;
			if (txtCustomerID.Text.Length == 0)
			{
				error = "Please enter a customerID";
				e.Cancel = true;
			}
			errorProvider1.SetError((Control)sender, error);
		}
		#endregion

		protected override void OnSave()
		{
			VienDongShippingModel model = new VienDongShippingModel();
			var obj = new VienDongShipping();

			obj.DateCreated = DateTime.Now;
			obj.CreatedId = Guid.NewGuid();
			obj.ModifiedId = Guid.NewGuid();
			obj.Modified = DateTime.Now;

			//obj.ServiceType = checkBox1.Checked;
			obj.TotalPakage = txtTotalPackage.Text;
			obj.Length = Convert.ToInt16(txtLenght.Text);
			obj.Width = Convert.ToInt16(txtWidth.Text);
			obj.Height = Convert.ToInt16(txtHeight.Text);
			obj.DeclaredValue = Convert.ToDecimal(txtDeclaredValue.Text);
			obj.InsuranceAmount = Convert.ToDecimal(txtInsurance.Text);
			obj.UnitPrice = Convert.ToDecimal(txtUnitPrice.Text);
			obj.TaxableAmount = Convert.ToDecimal(txtTaxableAmount.Text);
			obj.ExtractCharge = Convert.ToDecimal(txtExtraCharge.Text);
			obj.SenderDriverLicenseId = txtSenderDriver.Text;

			var customerSender = new Customer();
			customerSender.LastName = txtLastNameSender.Text;
			customerSender.MiddleName = txtMiddleNameSender.Text;
			customerSender.FirstName = txtFirstNameSender.Text;
			customerSender.Address = txtAddressSender.Text;
			customerSender.City = txtCitySender.Text;
			customerSender.State = txtStateSender.Text;
			customerSender.ZipCode = txtZipCodeSender.Text;
			customerSender.Phone = txtPhoneSender.Text;
			customerSender.Email = txtEmailSender.Text;

			var customerRecepient = new Customer();
			customerRecepient.LastName = txtLastNameReceive.Text;
			customerRecepient.MiddleName = txtMiddleNameReceive.Text;
			customerRecepient.FirstName = txtFirstNameReceive.Text;
			customerRecepient.Address = txtAddressSender.Text;
			customerRecepient.City = txtCityReceive.Text;
			customerRecepient.State = txtStateReceive.Text;
			customerRecepient.ZipCode = txtZipcodeReceive.Text;
			customerRecepient.Phone = txtPhoneReceive.Text;
			customerRecepient.Email = txtEmailReceive.Text;

			model.Add(customerSender, customerRecepient, obj);
		}

		private void btnUpdate_Click(object sender, EventArgs e)
		{
			Save();
		}
	}
}
